define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'wdsxh/activity_refund/index' + location.search,
                    add_url: 'wdsxh/activity_refund/add',
                    edit_url: 'wdsxh/activity_refund/edit',
                    del_url: 'wdsxh/activity_refund/del',
                    multi_url: 'wdsxh/activity_refund/multi',
                    import_url: 'wdsxh/activity_refund/import',
                    table: 'wdsxh_activity_refund',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        //{checkbox: true},
                        {field: 'id', title: __('Id')},
                        //{field: 'user.nickname', title: __('用户昵称'), operate: 'LIKE'},
                        //{field: 'user.avatar', title: __('用户头像'), operate: 'LIKE', events: Table.api.events.image, formatter: Table.api.formatter.image},
                        {field: 'wdsxhactivity.title', title: __('Wdsxhactivity.title'), operate: 'LIKE'},
                        {field: 'wdsxhmember.name', title: __('Wdsxhmember.name'), operate: 'LIKE'},
                        {field: 'wdsxhmember.mobile', title: __('会员电话'), operate: 'LIKE'},
                        {field: 'wdsxhmember.picture', title: __('Wdsxhmember.picture'), events: Table.api.events.image, formatter: Table.api.formatter.image},

                        {field: 'wdsxhactivityapply.money', title: __('Wdsxhactivityapply.money'), operate:'BETWEEN'},
                        {field: 'money', title: __('Money'), operate:'BETWEEN'},
                        {field: 'status', title: __('Status'), searchList: {"0":__('Status 0'),"1":__('Status 1'),"2":__('Status 2')}, formatter: Table.api.formatter.status},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'disposetime', title: __('处理时间'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        //{field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                        {
                            field: 'buttons',
                            width: "120px",
                            title: __('操作'),
                            table: table,
                            events: Table.api.events.operate,
                            buttons: [
                                {
                                    name: 'agree',
                                    text: __('确认退款'),
                                    title: __('确认退款'),
                                    classname: 'btn btn-xs btn-info btn-magic btn-ajax',
                                    icon: 'fa fa-check',
                                    url: 'wdsxh/activity_refund/agree',
                                    confirm: '确认并同意退款？退款后费用将原路退回',
                                    visible:function (row){
                                        if(row.status == 0){
                                            return true;
                                        }else{
                                            return false;
                                        }
                                    },
                                    success: function (data, ret) {
                                        $("#table").bootstrapTable('refresh',{});
                                    },
                                    error: function (data, ret) {
                                        Toastr.error(ret.msg);
                                        return false;
                                    }
                                },
                                {
                                    name: 'refuse',
                                    text: __('拒绝退款'),
                                    title: __('拒绝退款'),
                                    classname: 'btn btn-xs btn-danger btn-magic btn-ajax',
                                    icon: 'fa fa-close',
                                    url: 'wdsxh/activity_refund/refuse',
                                    confirm: '确认拒绝退款？',
                                    visible:function (row){
                                        if(row.status == 0){
                                            return true;
                                        }else{
                                            return false;
                                        }
                                    },
                                    success: function (data, ret) {
                                        $("#table").bootstrapTable('refresh',{});
                                    },
                                    error: function (data, ret) {
                                        Toastr.error(ret.msg);
                                        return false;
                                    }
                                },
                                {
                                    name: 'del',
                                    icon: 'fa fa-trash',
                                    title: __('删除'),
                                    text: __('删除'),
                                    extend: 'data-toggle="tooltip"',
                                    classname: 'btn btn-xs btn-danger btn-delone'
                                }
                            ],
                            formatter: Table.api.formatter.buttons
                        }
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});